package com.donquijote.spring6.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author 421527548@qq.com
 * @version V1.0
 * @title
 * @description
 * @date 2022-11-15 16:31
 */
public class User implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware , InitializingBean,DisposableBean {

    public User() {
        System.out.println("第一步：无参数构造方法执行");
    }

    private String name;

    public void setName(String name) {
        this.name = name;
        System.out.println("第二步：给对象的参数赋值");
    }

    public void init_method(){
        System.out.println("第六步：初始化方法");
    }

    @Override
    public String toString() {
        System.out.println("第八步：使用Bean");
        return "User{" +
                "name='" + name + '\'' +
                '}';
    }

    public void destroy_method(){
        System.out.println("第十步：Bean销毁");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("第三步：Bean的类加载器" + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("第三步:Bean工厂对象" + beanFactory);
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("第三步：Bean的名字" + s);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("第五步：InitializingBean接口的afterPropertiesSet执行");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("第九步：DisposableBean destroy 被自动调用");
    }


}
